package edu.zut.cs.software.cms.module.attendance.service.impl;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.zut.cs.software.cms.base.service.impl.GenericManagerImpl;
import edu.zut.cs.software.cms.module.attendance.dao.AttendanceDao;
import edu.zut.cs.software.cms.module.attendance.domain.Attendance;
import edu.zut.cs.software.cms.module.attendance.service.AttendanceManager;

/**
 * 
 * @author 清风依旧
 *
 */
@Service
public class AttendanceManagerImpl extends GenericManagerImpl<Attendance, Long> implements AttendanceManager {
	AttendanceDao attendanceDao;

	//delete
	@Override
	public List<Attendance> getList() {
		return (List<Attendance>)this.dao.findAll();
	}
	@Override
	public Optional<Attendance> findByAttendanceId(Long attendanceId) {
		Optional<Attendance> result=this.attendanceDao.findById(attendanceId);
		return result;
	}
	@Override
	public Boolean deleteById(Long attendanceId) {
		Optional<Attendance> attendance=this.dao.findById(attendanceId);
		if (attendance.equals(Optional.empty())) {
			return false;
		}else {
			this.dao.delete(attendance.get());
			return true;
		}
	}
	
	//modify
	@Override
	public boolean modifyById(long id,String status) {
		Attendance attendance=new Attendance();
		attendance=attendanceDao.modifyById(id);
		attendance.setStatus(status);		
		return true;
	}
	
	@Override
	public boolean IfExist(String name) {
		//数据存在返回false
		//数据不存在返回true
		if((attendanceDao.IfOneExist(name))>0) 
			return false;
		else
			return true;
	}
	
	@Autowired
	public void setAttendanceDao(AttendanceDao attendanceDao) {
		this.attendanceDao = attendanceDao;
		this.dao = this.attendanceDao;
	}
}
